'use strict';

angular.module('vistrack', [
  'ngStorage',
  'ngRoute',
  'ngSanitize',
  'smart-table',
  'upyun',
  'angular-loading-bar',
  'vistrackDirectives',
  'baseservice',
  'homecontroller',
  'usercontroller',
  'hospitalcontroller',
  'doctorcontroller',
  'patientcontroller',
  'vistrackcontroller',
  'patientservice',
  'doctorservice',
  'hospitalservice',
  'mainservice',
  'officeservice',
  'officecontroller',
  'provinceservice',
  'diseaseservice',
  'vistrackservice',
  'hospitalaggregatecontroller',
  'hospitalaggregateservice',
  'officeaggregatecontroller',
  'officeaggregateservice',
  'doctoraggregatecontroller',
  'doctoraggregateservice',
  'marketcontroller',
  'marketservice',
  'patientdoctorcontroller',
  'researchcontroller',
  'researchservice',
  'vistrackviewcontroller',
  'feecontroller',
  'feeservice',
  'labfeecontroller',
  'labfeeservice',
  'statisticcontroller',
  'statisticservice',
  'simditor',
  'materialcontroller',
  'materialdtlcontroller',
  'materialservice',
  'meservice',
  'mecontroller',
  'ui.bootstrap.datetimepicker',
  'ui.bootstrap.pagination'
]).config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
    $routeProvider.
      when('/', {
        templateUrl: 'partials/home.html',
        controller: 'HomeCtrl'
      }).
      when('/signin', {
        templateUrl: 'partials/signin.html',
        controller: 'HomeCtrl'
      }).
      when('/signup', {
        templateUrl: 'partials/signup.html',
        controller: 'HomeCtrl'
      }).
      when('/me', {
        templateUrl: 'partials/me.html',
        controller: 'HomeCtrl'
      }).
      when('/create_user', {
        templateUrl: 'partials/create_user.html',
        controller: 'UserCtrl'
      }).
      when('/update_user', {
        templateUrl: 'partials/create_user.html',
        controller: 'UserCtrl'
      }).
      when('/user_list', {
        templateUrl: 'partials/user_list.html',
        controller: 'UserCtrl'
      }).
      when('/hospital_list', {
        templateUrl: 'partials/hospital_list.html',
        controller: 'HospitalCtrl'
      }).
      when('/create_hospital', {
        templateUrl: 'partials/create_hospital.html',
        controller: 'HospitalCtrl'
      }).
      when('/update_hospital', {
        templateUrl: 'partials/create_hospital.html',
        controller: 'HospitalCtrl'
      }).
      when('/office_list', {
        templateUrl: 'partials/office_list.html',
        controller: 'OfficeCtrl'
      }).
      when('/create_office', {
        templateUrl: 'partials/create_office.html',
        controller: 'OfficeCtrl'
      }).
      when('/update_office', {
        templateUrl: 'partials/create_office.html',
        controller: 'OfficeCtrl'
      }).
      when('/doctor_list', {
        templateUrl: 'partials/doctor_list.html',
        controller: 'DoctorCtrl'
      }).
      when('/create_doctor', {
        templateUrl: 'partials/create_doctor.html',
        controller: 'DoctorCtrl'
      }).
      when('/update_doctor', {
        templateUrl: 'partials/create_doctor.html',
        controller: 'DoctorCtrl'
      }).
      when('/add_patient', {
        templateUrl: 'partials/add_patient.html',
        controller: 'PatientCtrl'
      }).
      when('/create_vistrack', {
        templateUrl: 'partials/create_vistrack.html',
        controller: 'VistrackCtrl'
      }).
      when('/hospital_aggregate', {
        templateUrl: 'partials/hospital_aggregate.html',
        controller: 'HosptialAggregateCtrl'
      }).
      when('/mkt_hospital_aggregate', {
        templateUrl: 'partials/market_hospital_aggregate.html',
        controller: 'MarketCtrl'
      }).
      when('/office_aggregate/:param', {
        templateUrl: 'partials/office_aggregate.html',
        controller: 'OfficeAggregateCtrl'
      }).
      when('/doctor_aggregate/:param', {
        templateUrl: 'partials/doctor_aggregate.html',
        controller: 'DoctorAggregateCtrl'
      }).
      when('/doctor_list2/:param', {
        templateUrl: 'partials/doctor_list_2.html',
        controller: 'DoctorCtrl'
      }).
      when('/vistrack/:param', {
        templateUrl: 'partials/view_vistrack.html',
        controller: 'VistrackViewCtrl'
      }).
      when('/update_patient', {
        templateUrl: 'partials/add_patient.html',
        controller: 'PatientCtrl'
      }).
      when('/patient_list/:param', {
        templateUrl: 'partials/patient_list.html',
        controller: 'PatientDoctorCtrl'
      }).
      when('/patient_list', {
        templateUrl: 'partials/patient_list2.html',
        controller: 'PatientCtrl'
      }).
      when('/market_list/:param', {
        templateUrl: 'partials/market_list.html',
        controller: 'MarketCtrl'
      }).
      when('/create_market_record/:param/:action', {
        templateUrl: 'partials/addmarket_record.html',
        controller: 'MarketCtrl'
      }).
      when('/create_doctor_research', {
        templateUrl: 'partials/adddoctor_research.html',
        controller: 'ResearchCtrl'
      }).
      when('/update_doctor_research', {
        templateUrl: 'partials/adddoctor_research.html',
        controller: 'ResearchCtrl'
      }).
      when('/research_list/:param', {
        templateUrl: 'partials/research_list.html',
        controller: 'ResearchCtrl'
      }).
      when('/research_list', {
        templateUrl: 'partials/research_list.html',
        controller: 'ResearchCtrl'
      }).
      when('/add_fee', {
        templateUrl: 'partials/addpatient_fee.html',
        controller: 'FeeCtrl'
      }).
      when('/patient_fee_list', {
        templateUrl: 'partials/patient_fee_list.html',
        controller: 'FeeCtrl'
      }).
      when('/update_patient_fee', {
      templateUrl: 'partials/updatepatient_fee.html',
      controller: 'FeeCtrl'
      }).
      when('/add_labfee', {
        templateUrl: 'partials/addlab_fee.html',
        controller: 'LabFeeCtrl'
      }).when('/lab_fee_list', {
      templateUrl: 'partials/lab_fee_list.html',
      controller: 'LabFeeCtrl'
      }).when('/doctor_statistic', {
          templateUrl: 'partials/statistic_doctor.html',
          controller: 'StatisticCtrl'
      }).
      when('/hospital_statistic', {
          templateUrl: 'partials/statistic_hospital.html',
          controller: 'StatisticCtrl'
      }).
      when('/create_material', {
          templateUrl: 'partials/create_material.html',
          controller: 'MaterialCtrl'
      }).
      when('/material_list', {
        templateUrl: 'partials/material_list.html',
        controller: 'MaterialCtrl'
      }).
      when('/material_dtl/:param', {
        templateUrl: 'partials/material_detail.html',
        controller: 'MaterialDtlCtrl'
      }).
      when('/me', {
        templateUrl: 'partials/me.html',
        controller: 'MeCtrl'
      }).when('/', {
        redirectTo: '/me'
      }).
      otherwise({
        redirectTo: '#/me'
      });

    $httpProvider.interceptors.push(function($rootScope, $q, $window) {
      return {
        'request': function (config) {
          config.headers = config.headers || {};
          if ($window.sessionStorage.token) {
            config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
          }
          return config;
        },
        'responseError': function(response) {
          if(response.status === 401 || response.status === 403) {
            window.location = '#/signin';
            alert(response.data.message);
          }
          return $q.reject(response);
        }
      };
    });
  }]);
